package br.urca.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.EquivalenciaDAO;
import br.urca.model.Equivalencia;

@Transactional
public class JPAEquivalenciaDAO implements EquivalenciaDAO {
	
	private EntityManager manager;
	
	public JPAEquivalenciaDAO() {
		this(null);
	}
	
	@Inject
	public JPAEquivalenciaDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public List<Equivalencia> getListEquivalencia(String codDisciplina) {
		try {
			return this.manager.createQuery(
					"SELECT e FROM Equivalencia e "
							+ "WHERE e.id.codDisciplina = :codigo ",
					Equivalencia.class).getResultList();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
